package com.ehotting.edsta.circuitDesign.gen.arguments.helper;

import com.ehotting.edsta.circuitDesign.bean.request.RequestCodeExecute;
import com.ehotting.edsta.circuitDesign.gen.ScriptConstants;
import com.ehotting.edsta.circuitDesign.gen.ScriptLogger;
import com.ehotting.edsta.circuitDesign.gen.element.helper.ElementScriptHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ArgumentScriptHelper {



    public String genMainMethod(String methodBody, String callBody, RequestCodeExecute inputParam){
        StringBuffer buf = new StringBuffer();
        buf.append(ScriptConstants.defineImport());
        buf.append(methodBody);
        buf.append(ScriptConstants.LINE);
        buf.append("def ");
        buf.append(genMethodNameAndArgument(genMainName(), inputParam.getArgumentsList()));
        buf.append( "{");
        buf.append(ScriptConstants.LINE);
        buf.append(callBody);
        buf.append(ScriptConstants.LINE);
        buf.append("};");
        String script = buf.toString();
        ScriptLogger.info(script);
        return script;
    }

    public String genMethodNameAndArgument(String methodName, List<String> inputParamList){
        StringBuffer buf = new StringBuffer();
        buf.append(methodName).append("(");
        for (String argName : inputParamList){
            buf.append(argName).append(",");
        }
        buf.append("ctx,all");
        buf.append( ")");

        return buf.toString();
    }

    public String genMainName(){
        return "main_argument";
    }


}
